<?php
/**���
 *
 * @link file.php
 * @author snowfir mailto:baige@ppstream.com
 * @date 13-1-16 ����3:54
 */

include "header.php";

header('Content-Type: text/html;charset=utf-8');

$m = new m;
$_GET['act'] = $_GET['act'] ? $_GET['act'] : "index";
$m->$_GET['act']();
class m
{
    function index(){
        $url_arr = array(
        's1.izhushou.cn',
        's2.izhushou.cn',
        's3.izhushou.cn');
        $id = $_GET['id'];
        $status = isset($_GET['status']) ? intval($_GET['status']) : 0;
        $status_arr = array(
            '0' => "下载",
            '1' => "等待下载",
            '2' => "下载中",
            '3' => "暂停下载",
            '4' => "下载失败",
            '5' => "安装",
            '6' => "更新",
            '7' => "等待安装",
            '8' => "安装中",
            '9' => "安装中",
            '10' => "安装失败",
            '11' => "已安装"
        );
        $stat = !empty($status_arr[$status]) ? $status_arr[$status]:'����';

        $com_show = $_COOKIE['com_'.$id] == 1 ? 1 : 0;

        $conn_mysql = _mysqllogon('Mysql_102');
        //mysql_query("SET NAMES 'gbk'");
        $sql = "select i.ID,i.APP_NAME,i.APP_TITLE,i.BUNDLE_VERSION,i.COPYRIGHT,g.GENRE,
                         i.VERS_CONTENT,i.APP_SIZE,i.PIC,i.IMGS,i.APP_URL,i.SCORE,i.VERSION_ID,
                         i.CONTENT,i.BODY_CONTENT,i.IPAD_NO,i.IPHONE_NO,i.APP_PRICE,
                        date_format(i.UPDATE_TIME,'%Y-%m-%d') as UPDATE_TIME
                         from ios_apps_info i,ios_apps_genre g
            		     where i.genre_id = g.id
            		     and i.id = :id";
        $stmt = _mysqlparse($conn_mysql, $sql);
        _mysqlbindbyname($stmt, ':id', $id);
        _mysqlexecute($stmt);
        $_row = mysql_fetch_assoc($stmt);
        $_row['PIC'] = str_replace('iosfile.izhushou.cn',$url_arr[array_rand($url_arr,1)],$_row['PIC']);
        $_row['ICON'] = str_replace('iosfile.izhushou.cn',$url_arr[array_rand($url_arr,1)],$_row['ICON']);
        $app_info = $_row;
        $score = explode(',', $app_info['SCORE']);
        $imgs = unserialize($app_info['IMGS']);
        $type_arr = array(
            '1' => 'iPhone ',
            '2' => 'iPad ',
            '3' => '',
        );
        if($imgs['iPhone'] && $imgs['iPad'])
        {
            $img_arr = $imgs['iPhone'];
            $type = 3;
        }else if($imgs['iPhone']){
            $img_arr = $imgs['iPhone'];
            $type = 1;
        }else if($imgs['iPad']){
            $img_arr = $imgs['iPad'];
            $type = 2;
        }

        $com_array = $this->get_list($id,1,2);
        $com_arr = $com_array['list'];

        $star_msg = array(
            1 => '讨厌',
            2 => '不喜欢',
            3 => '还可以',
            4 => '喜欢',
            5 => '很喜欢'
        );

        include "tp/show.html";
    }


    /**
     * @desc �加载评论下一页
     * ����
     *
     * @author snowfir mailto:baige@ppstream.com
     * @date 2013-3-21 11:32
     */
    function get_list($app_id = 0,$page_id = 1,$type = 1) {
        $type = $type ? $type : 1;
        $app_id = $app_id ? $app_id : $_GET['app_id'];
        if(!$app_id){
            $com_list = array();
            if($type == 1){
                include "com_list.php";
            }else{
                return array('total'=>'0','pages'=>'1','list'=>$com_list);
            }
        }else{
            $star_msg = array(
                1 => '讨厌',
                2 => '不喜欢',
                3 => '还可以',
                4 => '喜欢',
                5 => '很喜欢'
            );
            $_GET['pageID'] = isset($_GET['page_id']) ? max(intval($_GET['page_id']), 1) : $page_id;
            $page_ids = $_GET['pageID'];
            $conn_mysql = _mysqllogon('Mysql_102');
            //mysql_query("SET NAMES 'gbk'");
            $sql_t = "select count(id) as TOTAL from ios_apps_comment where app_id = :app_id and status = 1";
            $stmt_t = _mysqlparse($conn_mysql, $sql_t);
            _mysqlbindbyname($stmt_t, ':app_id', $app_id);
            _mysqlexecute($stmt_t);
            $t_row = mysql_fetch_assoc($stmt_t);
            $total = intval($t_row['TOTAL']);

            $size = 10;
            $this->pageObj = new page($total, $size);
            $sql_a = "select ID,RATING,COM_TITLE,CONTENT,USER_NAME,
                        date_format(ADD_TIME,'%m-%d-%Y') as ADD_TIME,
                        ADD_TIME AS ADD_TIME_F from ios_apps_comment
                        where app_id = :app_id and status = 1 order by add_time_f desc,order_by asc";
            $sql_a = $sql_a . ' LIMIT ' . $this->pageObj->limit_1 . ',' . $this->pageObj->limit_2;
            $stmt_a = _mysqlparse($conn_mysql, $sql_a);
            _mysqlbindbyname($stmt_a, ':app_id', $app_id);
            _mysqlexecute($stmt_a);
            $com_list = array();
            while ($a_row = mysql_fetch_assoc($stmt_a)) {
                $com_list[] = $a_row;
            }
            if($type == 1){
                include "com_list.php";
            }else{
                return array('total'=>$total,'pages'=>'1','pages'=>$this->pageObj->pages,'list'=>$com_list);
            }
        }
    }
}